package com.example.travel_front.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.travel_front.Adapter.CaregiverAdapter;
import com.example.travel_front.Model.Caregiver;
import com.example.travel_front.R;


import java.util.ArrayList;
import java.util.List;

public class CaregiverFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_caregiver, container, false);

        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        List<Caregiver> staffList = getStaffList();
        CaregiverAdapter adapter = new CaregiverAdapter(staffList, getContext());
        recyclerView.setAdapter(adapter);
        // Initialize spinners
        Spinner spinnerDistance = view.findViewById(R.id.spinnerDistance);
        Spinner spinnerPrice = view.findViewById(R.id.spinnerPrice);
        Spinner spinnerGender = view.findViewById(R.id.spinnerGender);

        // Set up the adapters for each spinner with example data
        setupSpinner(spinnerDistance, new String[]{"1 km", "5 km", "10 km"});
        setupSpinner(spinnerPrice, new String[]{"$100-500", "$500-1000", "$1000+"});
        setupSpinner(spinnerGender, new String[]{"Male", "Female", "Any"});

        return view;
    }


    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    private List<Caregiver> getStaffList() {
        // TODO: 实现从数据库或API获取护理之家列表的逻辑
        List<Caregiver> list = new ArrayList<>();
        list.add(new Caregiver("https://jdhn.oss-cn-hangzhou.aliyuncs.com/WechatIMG541.jpg", "Jie Shen", 26, "Male", 3, "Love Nursing Home", "Cooking, Massage",1));
        list.add(new Caregiver("https://jdhn.oss-cn-hangzhou.aliyuncs.com/WechatIMG542.jpg", "Xiaoyu Wang", 30, "Fwale", 5, "Harmony Elder Care", "Physical Therapy, Elderly Care",2));
        list.add(new Caregiver("https://jdhn.oss-cn-hangzhou.aliyuncs.com/WechatIMG543.jpg", "Ling Bai", 40, "Female", 10, "Sunset Retirement", "Nursing, General Healthcare",3));
        list.add(new Caregiver("https://jdhn.oss-cn-hangzhou.aliyuncs.com/WechatIMG544.jpg", "Chen Wu", 35, "Male", 7, "Peaceful Stay", "Medication Management, First Aid",4));
        list.add(new Caregiver("https://jdhn.oss-cn-hangzhou.aliyuncs.com/WechatIMG545.png", "Ming Zhao", 28, "Female", 4, "Golden Years", "Recreational Activities, Social Care",5));
        return list;
    }

    private void setupSpinner(Spinner spinner, String[] items) {
        ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(),
                android.R.layout.simple_spinner_item, items);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }

}
